Partimos de una web de catastro en la que se reflejan los datos del edificio, sus referencias castastrales, ..., leemos la web, con la funcion read_html y obtenemos los nodos que contienen. Dichos nodos los vemos al inspeccionar directamente la web, donde vemos que cada uno de los datos que nos interesan estan en dentro de la etiqueta div.panel.panel-default.

library(rvest)

# cargamos la url de la pagina de catastro que procede de introducir la dirección en catastro: CALLE/NUMERO

url.catastro <-"https://www1.sedecatastro.gob.es/CYCBienInmueble/OVCListaBienes.aspx?via=VERACRUZ&tipoVia=CL&numero=25&kilometro=&bloque=&escalera=&planta=&puerta=&DescProv=MADRID&prov=28&muni=61&DescMuni=GALAPAGAR&TipUR=U&codvia=38&comVia=VERACRUZ%20(CALLE)&pest=urbana&from=OVCBusqueda&nomusu=%20&tipousu=&ZV=NO&ZR=NO&anyoZV=&tematicos=&anyotem=" 

tmp <- read_html(url.catastro) #lee la pagina web
tmp <- html_nodes(tmp, "div.panel.panel-default") # coge los nodos con div,panel.panel-default que son las referencia catastrales del cuadro (inspeccion de la web de catastro)

tmp1 <- read_html(url.catastro) #lee la pagina web
tmp1 <- html_nodes(tmp, "#ImgFachada0") # imagen de fachada

obtener el cuadro con las superficies por usos

library(rvest)

# cargamos la url de la pagina de catastro que procede de introducir la dirección en catastro: CALLE/NUMERO

url.catastrot <- "https://www1.sedecatastro.gob.es/CYCBienInmueble/OVCConCiud.aspx?del=28&mun=160&UrbRus=U&RefC=1826802VK1812N0001IF&Apenom=&esBice=&RCBice1=&RCBice2=&DenoBice=&from=nuevoVisor&ZV=NO&anyoZV="

tmpt <- read_html(url.catastrot) #lee la pagina web
tmpt <- html_nodes(tmpt, ".panel-body") # coge los nodos con .panel-body que son las superficies del cuadro (inspeccion de la web de catastro)
length(tmpt)
[1] 4
tmpt
{xml_nodeset (4)}
[1] <div id="ctl00_Contenido_panelCartografia" class="panel-body">\r\n        ...
[2] <div class="panel-body">\r\n\r\n              <div id="ctl00_Contenido_tb ...
[3] <div class="panel-body">\r\n\r\n\r\n                      <div id="ctl00_ ...
[4] <div class="panel-body">\r\n                 <div class="table-responsive ...
html_text(tmpt)
[1] "\r\n                            \r\n                                Cartografía Catastral\r\n\r\n                                  GML, croquis por plantas (FXCC), foto de fachada\r\n                            \r\n\r\n                                Otros visores cartográficos\r\n"                                                                                                                                                                                                                                                                                                                                                                                                              
[2] "\r\n\r\n              \r\n                    \r\n                 Referencia catastral1826802VK1812N0001IF copiar    código de barrasLocalizaciónCL ARROYO DE SAN JUAN 3928210 VALDEMORILLO (MADRID)ClaseUrbanoUso principalResidencialSuperficie construida ayuda383 m2Año construcción  1972\r\n\r\n\r\n\r\n\r\n                "                                                                                                                                                                                                                                                                                                                                                                     
[3] "\r\n\r\n\r\n                      \r\n                          \r\n                          \r\n                              \r\n\r\n                           \r\n                              \r\n                          \r\n                              CARTOGRAFÍA NO DISPONIBLE\r\n                              \r\n                          \r\n                        \r\n                        Parcela construida sin división horizontalLocalizaciónCL ARROYO DE SAN JUAN 39 GVALDEMORILLO (MADRID)Superficie gráfica2.026 m2\r\n                      \r\n                     \r\n                     \r\n                     \r\n                     \r\n                 "
[4] "\r\n                       \r\n            Uso principal\r\n\t\tEscalera\r\n\t\tPlanta\r\n\t\tPuerta\r\n\t\tSuperficie m2\r\n\t\tTipo Reforma\r\n\t\tFecha Reforma\r\n\tVIVIENDA\r\n\t\t1\r\n\t\t00\r\n\t\t01\r\n\t\t160\r\n\t\t \r\n\t\t\r\n\tOTROS USOS\r\n\t\tP\r\n\t\t00\r\n\t\tCE\r\n\t\t22\r\n\t\t \r\n\t\t\r\n\tVIVIENDA\r\n\t\t1\r\n\t\t01\r\n\t\t01\r\n\t\t143\r\n\t\t \r\n\t\t\r\n\tOTROS USOS\r\n\t\tP\r\n\t\t01\r\n\t\tCE\r\n\t\t9\r\n\t\t \r\n\t\t\r\n\tDEPORTIVO\r\n\t\t2\r\n\t\t00\r\n\t\t01\r\n\t\t49\r\n\t\t \r\n\t\t\r\n\t"                                                                                                                                                                                                                                          
html_text(tmpt[4])
[1] "\r\n                       \r\n            Uso principal\r\n\t\tEscalera\r\n\t\tPlanta\r\n\t\tPuerta\r\n\t\tSuperficie m2\r\n\t\tTipo Reforma\r\n\t\tFecha Reforma\r\n\tVIVIENDA\r\n\t\t1\r\n\t\t00\r\n\t\t01\r\n\t\t160\r\n\t\t \r\n\t\t\r\n\tOTROS USOS\r\n\t\tP\r\n\t\t00\r\n\t\tCE\r\n\t\t22\r\n\t\t \r\n\t\t\r\n\tVIVIENDA\r\n\t\t1\r\n\t\t01\r\n\t\t01\r\n\t\t143\r\n\t\t \r\n\t\t\r\n\tOTROS USOS\r\n\t\tP\r\n\t\t01\r\n\t\tCE\r\n\t\t9\r\n\t\t \r\n\t\t\r\n\tDEPORTIVO\r\n\t\t2\r\n\t\t00\r\n\t\t01\r\n\t\t49\r\n\t\t \r\n\t\t\r\n\t"
datoscatt<-as.data.frame(html_text(tmpt))
datoscatt
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           html_text(tmpt)
1                                                                                                                                                                                                                                                                                                                                                                                                               \r\n                            \r\n                                Cartografía Catastral\r\n\r\n                                  GML, croquis por plantas (FXCC), foto de fachada\r\n                            \r\n\r\n                                Otros visores cartográficos\r\n
2                                                                                                                                                                                                                                                                                                                                                                      \r\n\r\n              \r\n                    \r\n                 Referencia catastral1826802VK1812N0001IF copiar    código de barrasLocalizaciónCL ARROYO DE SAN JUAN 3928210 VALDEMORILLO (MADRID)ClaseUrbanoUso principalResidencialSuperficie construida ayuda383 m2Año construcción  1972\r\n\r\n\r\n\r\n\r\n                
3 \r\n\r\n\r\n                      \r\n                          \r\n                          \r\n                              \r\n\r\n                           \r\n                              \r\n                          \r\n                              CARTOGRAFÍA NO DISPONIBLE\r\n                              \r\n                          \r\n                        \r\n                        Parcela construida sin división horizontalLocalizaciónCL ARROYO DE SAN JUAN 39 GVALDEMORILLO (MADRID)Superficie gráfica2.026 m2\r\n                      \r\n                     \r\n                     \r\n                     \r\n                     \r\n                 
4                                                                                                                                                                                                                                           \r\n                       \r\n            Uso principal\r\n\t\tEscalera\r\n\t\tPlanta\r\n\t\tPuerta\r\n\t\tSuperficie m2\r\n\t\tTipo Reforma\r\n\t\tFecha Reforma\r\n\tVIVIENDA\r\n\t\t1\r\n\t\t00\r\n\t\t01\r\n\t\t160\r\n\t\t \r\n\t\t\r\n\tOTROS USOS\r\n\t\tP\r\n\t\t00\r\n\t\tCE\r\n\t\t22\r\n\t\t \r\n\t\t\r\n\tVIVIENDA\r\n\t\t1\r\n\t\t01\r\n\t\t01\r\n\t\t143\r\n\t\t \r\n\t\t\r\n\tOTROS USOS\r\n\t\tP\r\n\t\t01\r\n\t\tCE\r\n\t\t9\r\n\t\t \r\n\t\t\r\n\tDEPORTIVO\r\n\t\t2\r\n\t\t00\r\n\t\t01\r\n\t\t49\r\n\t\t \r\n\t\t\r\n\t
DT::datatable((datoscatt), fillContainer = TRUE, options = list(pageLength = 10))

————————————– FIN —————————————-

Podemos insertar un pantallazo entero de la web y la guardamos en nuestro directorio

webshot ( "https://www1.sedecatastro.gob.es/CYCBienInmueble/OVCListaBienes.aspx?via=VERACRUZ&tipoVia=CL&numero=25&kilometro=&bloque=&escalera=&planta=&puerta=&DescProv=MADRID&prov=28&muni=61&DescMuni=GALAPAGAR&TipUR=U&codvia=38&comVia=VERACRUZ%20(CALLE)&pest=urbana&from=OVCBusqueda&nomusu=%20&tipousu=&ZV=NO&ZR=NO&anyoZV=&tematicos=&anyotem=", 
          "C:/Users/polo/Desktop/AEVIU/0002/p1.png")

Vemos algunas propiedades de los nodos leidos de la web. Son en este caso, 90

length(tmpt)
[1] 4
tmpt
{xml_nodeset (4)}
[1] <div id="ctl00_Contenido_panelCartografia" class="panel-body">\r\n        ...
[2] <div class="panel-body">\r\n\r\n              <div id="ctl00_Contenido_tb ...
[3] <div class="panel-body">\r\n\r\n\r\n                      <div id="ctl00_ ...
[4] <div class="panel-body">\r\n                 <div class="table-responsive ...
vemos la clase. Logicamente son todos iguales, xml_node

sapply(tmpt, class)
[1] "xml_node" "xml_node" "xml_node" "xml_node"
vemos el primero

tmpt[[1]]
{html_node}
<div id="ctl00_Contenido_panelCartografia" class="panel-body">
[1] <table class="table text-left">\n<tr id="ctl00_Contenido_trMostrarCarto"> ...
Con la funcion html_text, pasamos a texto todos los nodos

datoscat<-as.data.frame(html_text(tmpt))

DT::datatable((datoscat), fillContainer = FALSE, options = list(pageLength = 10))

AHORA VAMOS HA HACER LO MISMO, PERO DE FORMA AUTOMATICA, PARTIENDO DE LOS DATOS DE LOCALIZACION DEL INMUEBLE.

DATOS A RELLENAR:

library(rvest)
library(stringr)


via <- "CL"
via1 <- "CALLE"
nombrecalle <- "VERACRUZ"
numero <- "22" 
DescProv <- "MADRID" 
pro <- "28"
DesMuni <- "GALAPAGAR" 
Cpodt <- "28260"



Ahora craeamos la direccion web de catastro partiendo de los datos anteriormente apuntado: Se ha realizado de forma desglosada para finalmente concatenar todas variables empleadas (forma mas didactica). A continuación obtenemos los datos deseados.

Nota, el nombrecalle tiene que ser una palabra

ww <- "https://www1.sedecatastro.gob.es/CYCBienInmueble/OVCListaBienes.aspx?via="


# nombrecalle<-gsub(" ", "@", nombrecalle)
# comvia<-gsub("@", "%20", nombrecalle)
# comvia<-paste(comvia, "%20", sep="")
# comvia

ee <- nombrecalle
rr <- "&tipoVia="

ss <- via
zz <- "&numero="
xx <- numero
yy <- "&kilometro=&bloque=&escalera=&planta=&puerta="

tt <- "&DescProv="
cc <- DescProv

vv <- "&DescMuni="
bb <- DesMuni

oo <- "&prov="
pp <- pro

nn <- "&TipUR=U"

gg <- "&comVia="
jj <- nombrecalle


lll <- "&pest=urbana&from=OVCBusqueda&nomusu=%20&tipousu=&ZV=NO&ZR=NO&anyoZV=&tematicos=&anyotem="

# (via)&pest=urbana&from=OVCBusqueda&nomusu=%20&tipousu=&ZV=NO&ZR=NO&anyoZV=&tematicos=&anyotem="

webcatastro <- paste(ww, ee, rr, ss, zz, xx, yy, tt, cc, oo, pp, vv, bb, nn, gg, jj, lll, sep="")
webcatastro
[1] "https://www1.sedecatastro.gob.es/CYCBienInmueble/OVCListaBienes.aspx?via=VERACRUZ&tipoVia=CL&numero=22&kilometro=&bloque=&escalera=&planta=&puerta=&DescProv=MADRID&prov=28&DescMuni=GALAPAGAR&TipUR=U&comVia=VERACRUZ&pest=urbana&from=OVCBusqueda&nomusu=%20&tipousu=&ZV=NO&ZR=NO&anyoZV=&tematicos=&anyotem="
tmp1 <- read_html(webcatastro) #lee la pagina web
tmp1 <- html_nodes(tmp1, "div.panel.panel-default") # coge los nodos con div,panel.panel-default que son las referencia catastrales del cuadro (inspeccion de la web de catastro)

head(html_text(tmp1))
[1] "5222210VK1952S0001JB     CL VERACRUZ 22 Es:D Pl:00 Pt:AResidencial  |             93 m2  |    5,19%  | 2000"
[2] "5222210VK1952S0002KZ     CL VERACRUZ 22 Es:D Pl:00 Pt:BResidencial  |            102 m2  |    5,80%  | 2000"
[3] "5222210VK1952S0003LX     CL VERACRUZ 22 Es:D Pl:00 Pt:CResidencial  |             80 m2  |    4,70%  | 2000"
[4] "5222210VK1952S0004BM     CL VERACRUZ 22 Es:D Pl:00 Pt:DResidencial  |             73 m2  |    4,13%  | 2000"
[5] "5222210VK1952S0007ME     CL VERACRUZ 22 Es:D Pl:01 Pt:AResidencial  |             97 m2  |    5,51%  | 2000"
[6] "5222210VK1952S0008QR     CL VERACRUZ 22 Es:D Pl:01 Pt:BResidencial  |            100 m2  |    5,75%  | 2000"
da<-html_text(tmp1)

nchar(da[1]) # cuantos caracteres tiene la primera fila?
[1] 107
head(substr(da, start = 0, stop = 20))    # Para extraer la subcadena desde el primero al caracter 20 es decir la referencia catastral.
[1] "5222210VK1952S0001JB" "5222210VK1952S0002KZ" "5222210VK1952S0003LX"
[4] "5222210VK1952S0004BM" "5222210VK1952S0007ME" "5222210VK1952S0008QR"
refcat <- substr(da[1], start = 0, stop = 14)      # Para extraer la subcadena desde el primero al caracter 14 es decir la referencia catastral del edificio.
refcat
[1] "5222210VK1952S"
inserta un pantallazo de la web

inserta la propia web de catastro en el formato html de Rmd

knitr::include_url(webcatastro)


incluir plano catatral

ww <- "https://www1.sedecatastro.gob.es/Cartografia/mapa.aspx?"

re <- "refcat="
ree <- refcat

ee <- nombrecalle
rr <- "&tipoVia="
ss <- via
zz <- "&numero="
xx <- numero
yy <- "&kilometro=&bloque=&escalera=&planta=&puerta="

tt <- "&DescProv="
cc <- DescProv

vv <- "&DescMuni="
bb <- DesMuni

oo <- "&prov="
pp <- pro

nn <- "&TipUR=U"

gg <- "&comVia="
jj <- nombrecalle

lll <- "&pest=urbana&from=OVCBusqueda&nomusu=%20&tipousu=&ZV=NO&ZR=NO&anyoZV=&tematicos=&anyotem="

# (via)&pest=urbana&from=OVCBusqueda&nomusu=%20&tipousu=&ZV=NO&ZR=NO&anyoZV=&tematicos=&anyotem="
# 
locacatastro <- paste(ww, re, ree, sep="")
locacatastro
[1] "https://www1.sedecatastro.gob.es/Cartografia/mapa.aspx?refcat=5222210VK1952S"
knitr::include_url(locacatastro)
webshot ( locacatastro, "C:/Users/polo/Desktop/AEVIU/0002/locacatastro.png")

library(spanish)
coo<-geocode_cadastral(ree, parse_files = FALSE)
coo
[1] "-4.00288119736999,40.57471475288"
library(stringr)

dir1<-strsplit(coo, ",")
dir1
[[1]]
[1] "-4.00288119736999" "40.57471475288"   
lng1<-as.numeric(dir1[[1]][[1]])
lat1<-as.numeric(dir1[[1]][[2]])
coord1<-c(lng1, lat1)
coord1
[1] -4 41
# Use with coords
# 
library(CatastRo)
library(spanish)
library(sp)
library(sf)

direcc<-catr_get_code_from_coords(coord1, srs = 4326)
t(direcc)
           [,1]       
munic      "GALAPAGAR"
catr_to    "28"       
catr_munic "061"      
catrcode   "28061"    
cpro       "28"       
cmun       "061"      
inecode    "28061"    
nm         "GALAPAGAR"
cd         "28"       
cmc        "61"       
cp         "28"       
cm         "61"       
require(knitr)
require(XLConnect)

testigospar<-read_excel("C:/Users/polo/Desktop/RegistroTestigos.xlsm", sheet = "parcela", range = ("A1:l7"))

kable((testigospar),
      "html", 
      col.names = c("numero","direccion", "m2p", "VOfertado", "UAdoptado", "RC", "telefono", "municipio", "lat", "long", "fecha", "web"),
      align = c("l","c","c","c","c","c","c","c","c","c","c","l"))%>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed"),
                full_width = F, 
                position = "float_left")%>%
  kable_styling(font_size = 10)%>%
  column_spec(1, bold=T, border_right = T)
numero direccion m2p VOfertado UAdoptado RC telefono municipio lat long fecha web
testigo1 GREGORIO PANADERO 25 726 180000 223 4692620VK1849S0001BG 622266544 COLMENAREJO 41 -4 2022-05-23 https://www.idealista.com/inmueble/94202287/
testigo 2 SARMIENTOS 3 1052 180000 154 3684401VK1838S0001KJ 606287773 COLMENAREJO 41 -4 2022-05-23 https://www.idealista.com/inmueble/97471374/
testigo 3 CARMELO RODRIGUEZ 12 930 215000 208 49936A2VK1849S0001WG 911369205 COLMENAREJO 41 -4 2022-05-23 https://www.idealista.com/inmueble/95704303/
testigo 4 PRADO IBARRA 23 2599 295000 102 4000538VK1940S0001ST 912184067 COLMENAREJO 41 -4 2022-05-23 https://www.idealista.com/inmueble/91822076/
testigo 5 NA NA NA NA NA NA COLMENAREJO NA NA 2022-05-23 NA
testigo 6 NA NA NA NA NA NA COLMENAREJO NA NA 2022-05-23 NA
options(knitr.kable.NA ="")
CRS("+init=epsg:4326")
Coordinate Reference System:
Deprecated Proj.4 representation: +proj=longlat +datum=WGS84 +no_defs 
WKT2 2019 representation:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]],
        ID["EPSG",6326]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433],
        ID["EPSG",8901]],
    CS[ellipsoidal,2],
        AXIS["longitude",east,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433,
                ID["EPSG",9122]]],
        AXIS["latitude",north,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433,
                ID["EPSG",9122]]],
    USAGE[
        SCOPE["unknown"],
        AREA["World."],
        BBOX[-90,-180,90,180]]] 
library(ggplot2)
# install.packages('ggspatial')
library(ggspatial)
library(CatastRo)
library(spanish)

s <- catr_atom_get_parcels("Valdemorillo",
to = "Madrid",
what = "zoning"     #o "parcel"
)

# La función coord_sf nos permite escoger otro sistema de coordenadas. Usando el argumento crs, es posible anular esta configuración y reproyectar los datos a cualquier proyección utilizando cualquier cadena PROJ4 válida

#  coord_sf(crs = "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000
#           +y_0=3210000 +ellps=GRS80 +units=m +no_defs ")
#           
 dat2 <- select(testigospar,
            latitud, longitud,DIRECCION)
 
names(dat2)<-c("lon","lat","DIRECCION")
           
# capap <- st_as_sf(x = dat2, 
#                  coords = c("lon", "lat"),
#                  crs = "+proj=longlat + datum=WGS84 + init=epsg:4326")
# capap

ggplot(s) +
# layer_spatial(capap, size = 3, col="red",alpha = 0.5)+
geom_sf() +
geom_sf(fill = "brown", color = "black") +
annotation_scale() +
annotation_north_arrow(location='tr') +
labs(
title = "Cadastral Zoning",
subtitle = "Valdemorillo, Madrid"
)


# usando la referencia catastral para localizar el inmueble
# 
rc <- catr_wfs_get_buildings_rc(ree)
# rc <- catr_wfs_get_parcels_neigh_parcel(ree)
library(ggplot2)
library(CatastRo)
ggplot(rc) +
geom_sf() +
geom_sf(fill = "brown", color = "black") +
# annotate("point", x = 4.00283, y = 40.57473, colour = "blue")+
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, size = 11))+
labs(title = "buscando referencia catastral")

sf::st_centroid(rc)
Simple feature collection with 1 feature and 24 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 420000 ymin: 4500000 xmax: 420000 ymax: 4500000
Projected CRS: ETRS89 / UTM zone 30N
                     gml_id beginLifespanVersion conditionOfConstruction
1 ES.SDGC.BU.5222210VK1952S  2010-11-05T00:00:00              functional
            beginning                 end endLifespanVersion
1 2000-01-01T00:00:00 2000-01-01T00:00:00               <NA>
                                                                             informationSystem
1 https://www1.sedecatastro.gob.es/CYCBienInmueble/OVCListaBienes.aspx?rc1=5222210&rc2=VK1952S
       reference        localId  namespace horizontalGeometryEstimatedAccuracy
1 5222210VK1952S 5222210VK1952S ES.SDGC.BU                                 0.1
  horizontalGeometryEstimatedAccuracy_uom horizontalGeometryReference
1                                       m                   footPrint
  referenceGeometry    currentUse numberOfBuildingUnits numberOfDwellings
1              TRUE 1_residential                    18                18
  numberOfFloorsAboveGround
1                      <NA>
                                                                                                                      documentLink
1 http://ovc.catastro.meh.es/OVCServWeb/OVCWcfLibres/OVCFotoFachada.svc/RecuperarFotoFachadaGet?ReferenciaCatastral=5222210VK1952S
  format sourceStatus officialAreaReference value value_uom
1   jpeg  NotOfficial        grossFloorArea  1789        m2
                geometry
1 POINT (415122 4492033)

FOTO DE FACHADA, se guarda en el el directorio indicado

ww <- "http://ovc.catastro.meh.es/OVCServWeb/OVCWcfLibres/OVCFotoFachada.svc/RecuperarFotoFachadaGet?ReferenciaCatastral="

ree <- refcat

fotocatastro <- paste(ww, ree, sep="")
fotocatastro
[1] "http://ovc.catastro.meh.es/OVCServWeb/OVCWcfLibres/OVCFotoFachada.svc/RecuperarFotoFachadaGet?ReferenciaCatastral=5222210VK1952S"
knitr::include_url(fotocatastro)
webshot ( fotocatastro, "C:/Users/polo/Desktop/AEVIU/0002/fotocatastro.png")

todas las RC de un municipio

coordenadas_catastro<-catr_ovc_get_cpmrc("9872023VH5797S")
t(coordenadas_catastro)
         [,1]                                             
xcoord   "-3.5"                                           
ycoord   "39"                                             
refcat   "9872023VH5797S"                                 
address  "CL GLORIA 51 SANTA CRUZ DE MUDELA (CIUDAD REAL)"
pc.pc1   "9872023"                                        
pc.pc2   "VH5797S"                                        
geo.xcen "-3.46328353028033"                              
geo.ycen "38.6401434830887"                               
geo.srs  "EPSG:4326"                                      
ldt      "CL GLORIA 51 SANTA CRUZ DE MUDELA (CIUDAD REAL)"
catr_ovc_get_rccoor(lat = 38.6196566583596, lon = -3.45624183836806, srs = 4326, verbose = FALSE)
# A tibble: 1 x 8
  refcat         address           pc.pc1 pc.pc2 geo.xcen geo.ycen geo.srs ldt  
  <chr>          <chr>             <chr>  <chr>     <dbl>    <dbl> <chr>   <chr>
1 13077A01800011 DS DISEMINADO  P~ 13077~ 18000~    -3.46     38.6 EPSG:4~ DS D~
ad <- catr_wfs_get_address_bbox(c(
233673, 4015968, 233761, 4016008
),
srs = 25830
)
library(ggplot2)
ggplot(ad) +
geom_sf()

# Using bbox
building <- catr_wfs_get_buildings_bbox(c(
376550,
4545424,
376600,
4545474
),
srs = 25830
)
library(ggplot2)
ggplot(building) +
geom_sf() +
labs(title = "Search using bbox")

rc1 <- catr_wfs_get_buildings_rc("6656601UL7465N")
library(ggplot2)
ggplot(rc1) +
geom_sf() +
labs(title = "Search using rc")

# With a bbox
pict <- catr_wms_get_layer(c(222500, 4019500, 223700, 4020700),
srs = 25830,
what = "parcel"
)
library(ggplot2)
library(mapSpain)
ggplot() +
layer_spatraster(pict)

parcels <- catr_wfs_get_parcels_neigh_parcel("3662303TF3136B")
# Transform
parcels <- sf::st_transform(parcels, 3857)
# Use styles
parcels_img <- catr_wms_get_layer(parcels,
what = "buildingpart",
bbox_expand = 0.3,
styles = "ELFCadastre"
)

ggplot() +
geom_sf(data = parcels, fill = "blue", alpha = 0.5) +
layer_spatraster(parcels_img)

# ========================================== PARA LAS DIRECCIONES 

m <- leaflet(height=400, width=800, options = leafletOptions(minZoom = 13, maxZoom = 17)) %>% addTiles(group = "OSM") %>%
  addTiles()%>%
  addCircles(lat = lat1, lng = lng1, fillColor = "red", color = "blue")%>%
  addMeasure(position = "topleft",
    primaryLengthUnit = "meters",
    primaryAreaUnit = "sqmeters",
    activeColor = "#3D535D",
    completedColor = "#7D4479",
    localization = "es")
m



# install.packages("mapdata")
library(mapdata)
library(ggplot2)
library(maps)
library(ggrepel)
library(tidyverse)

mapa_mundo <- map_data("world")

mapa_mundo %>%
  ggplot() +
  geom_polygon(aes( x= long, y = lat, group = group),
               fill = "brown",
               color = "white")

tabla de nivel superior que incluye información de todos las direcciones territoriales (excepto País Vasco y Navarra)

territorial_office<-catr_atom_get_address_db_all(
cache = TRUE,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE
)
territorial_office
# A tibble: 7,611 x 4
   territorial_office             url                  munic date               
   <chr>                          <chr>                <chr> <dttm>             
 1 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 2 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 3 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 4 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 5 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 6 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 7 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 8 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 9 Territorial office 02 Albacete http://www.catastro~ 0201~ 2022-03-14 00:00:00
10 Territorial office 02 Albacete http://www.catastro~ 0201~ 2022-03-14 00:00:00
# ... with 7,601 more rows
write.table(territorial_office, file = "territorial_office.csv", row.names = FALSE) # guarda un archivo excel
head(territorial_office$url, 10)
 [1] "http://www.catastro.minhap.es/INSPIRE/addresses/02/ES.SDGC.ad.atom_02.xml"
 [2] "http://www.catastro.minhap.es/INSPIRE/addresses/02/ES.SDGC.ad.atom_02.xml"
 [3] "http://www.catastro.minhap.es/INSPIRE/addresses/02/ES.SDGC.ad.atom_02.xml"
 [4] "http://www.catastro.minhap.es/INSPIRE/addresses/02/ES.SDGC.ad.atom_02.xml"
 [5] "http://www.catastro.minhap.es/INSPIRE/addresses/02/ES.SDGC.ad.atom_02.xml"
 [6] "http://www.catastro.minhap.es/INSPIRE/addresses/02/ES.SDGC.ad.atom_02.xml"
 [7] "http://www.catastro.minhap.es/INSPIRE/addresses/02/ES.SDGC.ad.atom_02.xml"
 [8] "http://www.catastro.minhap.es/INSPIRE/addresses/02/ES.SDGC.ad.atom_02.xml"
 [9] "http://www.catastro.minhap.es/INSPIRE/addresses/02/ES.SDGC.ad.atom_02.xml"
[10] "http://www.catastro.minhap.es/INSPIRE/addresses/02/ES.SDGC.ad.atom_02.xml"

txt 641

tmp_territorial <- read_html(territorial_office$url[[1]]) #lee la primera direccion xml
tmp_territorial
{html_document}
<html>
[1] <body><feed xmlns="http://www.w3.org/2005/Atom" xmlns:xsi="http://www.w3. ...

datos espaciales de todos los edificios pertenecientes a un mismo municipio

buildings_all<-catr_atom_get_buildings_db_all(
cache = TRUE,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE
)
head(buildings_all, 10)
# A tibble: 10 x 4
   territorial_office             url                  munic date               
   <chr>                          <chr>                <chr> <dttm>             
 1 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 2 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 3 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 4 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 5 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 6 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 7 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 8 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 9 Territorial office 02 Albacete http://www.catastro~ 0201~ 2022-03-14 00:00:00
10 Territorial office 02 Albacete http://www.catastro~ 0201~ 2022-03-14 00:00:00

datos espaciales de todas las parcelas pertenecientes a un mismo municipio

parcels_db_all<-catr_atom_get_parcels_db_all(
cache = TRUE,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE
)

head(parcels_db_all, 10)
# A tibble: 10 x 4
   territorial_office             url                  munic date               
   <chr>                          <chr>                <chr> <dttm>             
 1 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 2 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 3 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 4 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 5 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 6 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 7 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 8 Territorial office 02 Albacete http://www.catastro~ 0200~ 2022-03-14 00:00:00
 9 Territorial office 02 Albacete http://www.catastro~ 0201~ 2022-03-14 00:00:00
10 Territorial office 02 Albacete http://www.catastro~ 0201~ 2022-03-14 00:00:00
# usando con coordenadas
code_from_coords<-catr_get_code_from_coords(c(-16.25462, 28.46824), srs = 4326)
t(code_from_coords)
           [,1]                    
munic      "SANTA CRUZ DE TENERIFE"
catr_to    "38"                    
catr_munic "900"                   
catrcode   "38900"                 
cpro       "38"                    
cmun       "038"                   
inecode    "38038"                 
nm         "SANTA CRUZ DE TENERIFE"
cd         "38"                    
cmc        "900"                   
cp         "38"                    
cm         "38"                    
# usando sf
prov <- mapSpain::esp_get_prov("Caceres")
code_from_coords1<-catr_get_code_from_coords(prov)
t(code_from_coords1)
           [,1]    
munic      "MONROY"
catr_to    "10"    
catr_munic "128"   
catrcode   "10128" 
cpro       "10"    
cmun       "125"   
inecode    "10125" 
nm         "MONROY"
cd         "10"    
cmc        "128"   
cp         "10"    
cm         "125"   
munic<-catr_atom_get_address_db_to(
to = "Madrid",
cache = TRUE,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE
)

munic
# A tibble: 179 x 3
   munic                             url                     date               
   <chr>                             <chr>                   <dttm>             
 1 28002-AJALVIR addresses           http://www.catastro.mi~ 2022-03-11 00:00:00
 2 28003-ALAMEDA DEL VALLE addresses http://www.catastro.mi~ 2022-03-11 00:00:00
 3 28005-ALCALA DE HENARES addresses http://www.catastro.mi~ 2022-03-11 00:00:00
 4 28006-ALCOBENDAS addresses        http://www.catastro.mi~ 2022-03-11 00:00:00
 5 28007-ALCORCON addresses          http://www.catastro.mi~ 2022-03-11 00:00:00
 6 28008-ALDEA DEL FRESNO addresses  http://www.catastro.mi~ 2022-03-11 00:00:00
 7 28009-ALGETE addresses            http://www.catastro.mi~ 2022-03-11 00:00:00
 8 28010-ALPEDRETE addresses         http://www.catastro.mi~ 2022-03-11 00:00:00
 9 28011-AMBITE addresses            http://www.catastro.mi~ 2022-03-11 00:00:00
10 28012-ANCHUELO addresses          http://www.catastro.mi~ 2022-03-11 00:00:00
# ... with 169 more rows
head(munic$url,10)
 [1] "http://www.catastro.minhap.es/INSPIRE/Addresses/28/28002-AJALVIR/A.ES.SDGC.AD.28002.zip"          
 [2] "http://www.catastro.minhap.es/INSPIRE/Addresses/28/28003-ALAMEDA DEL VALLE/A.ES.SDGC.AD.28003.zip"
 [3] "http://www.catastro.minhap.es/INSPIRE/Addresses/28/28005-ALCALA DE HENARES/A.ES.SDGC.AD.28005.zip"
 [4] "http://www.catastro.minhap.es/INSPIRE/Addresses/28/28006-ALCOBENDAS/A.ES.SDGC.AD.28006.zip"       
 [5] "http://www.catastro.minhap.es/INSPIRE/Addresses/28/28007-ALCORCON/A.ES.SDGC.AD.28007.zip"         
 [6] "http://www.catastro.minhap.es/INSPIRE/Addresses/28/28008-ALDEA DEL FRESNO/A.ES.SDGC.AD.28008.zip" 
 [7] "http://www.catastro.minhap.es/INSPIRE/Addresses/28/28009-ALGETE/A.ES.SDGC.AD.28009.zip"           
 [8] "http://www.catastro.minhap.es/INSPIRE/Addresses/28/28010-ALPEDRETE/A.ES.SDGC.AD.28010.zip"        
 [9] "http://www.catastro.minhap.es/INSPIRE/Addresses/28/28011-AMBITE/A.ES.SDGC.AD.28011.zip"           
[10] "http://www.catastro.minhap.es/INSPIRE/Addresses/28/28012-ANCHUELO/A.ES.SDGC.AD.28012.zip"         
url <- ( "http://www.catastro.minhap.es/INSPIRE/Addresses/28/28047-COLLADO VILLALBA/A.ES.SDGC.AD.28047.zip")

destination<- "C:/Users/polo/OneDrive/ZZZ/vivienda/catastro/A.ES.SDGC.AD.28047.zip"

download.file(url, destination)
buildings<-catr_atom_get_buildings_db_to(
  to = "Madrid",
  cache = TRUE,
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)
buildings
# A tibble: 179 x 3
   munic                             url                     date               
   <chr>                             <chr>                   <dttm>             
 1 28002-AJALVIR buildings           http://www.catastro.mi~ 2022-03-11 00:00:00
 2 28003-ALAMEDA DEL VALLE buildings http://www.catastro.mi~ 2022-03-11 00:00:00
 3 28005-ALCALA DE HENARES buildings http://www.catastro.mi~ 2022-03-11 00:00:00
 4 28006-ALCOBENDAS buildings        http://www.catastro.mi~ 2022-03-11 00:00:00
 5 28007-ALCORCON buildings          http://www.catastro.mi~ 2022-03-11 00:00:00
 6 28008-ALDEA DEL FRESNO buildings  http://www.catastro.mi~ 2022-03-11 00:00:00
 7 28009-ALGETE buildings            http://www.catastro.mi~ 2022-03-11 00:00:00
 8 28010-ALPEDRETE buildings         http://www.catastro.mi~ 2022-03-11 00:00:00
 9 28011-AMBITE buildings            http://www.catastro.mi~ 2022-03-11 00:00:00
10 28012-ANCHUELO buildings          http://www.catastro.mi~ 2022-03-11 00:00:00
# ... with 169 more rows
buildings$url
  [1] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28002-AJALVIR/A.ES.SDGC.BU.28002.zip"                       
  [2] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28003-ALAMEDA DEL VALLE/A.ES.SDGC.BU.28003.zip"             
  [3] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28005-ALCALA DE HENARES/A.ES.SDGC.BU.28005.zip"             
  [4] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28006-ALCOBENDAS/A.ES.SDGC.BU.28006.zip"                    
  [5] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28007-ALCORCON/A.ES.SDGC.BU.28007.zip"                      
  [6] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28008-ALDEA DEL FRESNO/A.ES.SDGC.BU.28008.zip"              
  [7] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28009-ALGETE/A.ES.SDGC.BU.28009.zip"                        
  [8] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28010-ALPEDRETE/A.ES.SDGC.BU.28010.zip"                     
  [9] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28011-AMBITE/A.ES.SDGC.BU.28011.zip"                        
 [10] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28012-ANCHUELO/A.ES.SDGC.BU.28012.zip"                      
 [11] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28013-ARANJUEZ/A.ES.SDGC.BU.28013.zip"                      
 [12] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28014-ARGANDA DEL REY/A.ES.SDGC.BU.28014.zip"               
 [13] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28015-ARROYOMOLINOS/A.ES.SDGC.BU.28015.zip"                 
 [14] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28017-BATRES/A.ES.SDGC.BU.28017.zip"                        
 [15] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28018-BECERRIL DE LA SIERRA/A.ES.SDGC.BU.28018.zip"         
 [16] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28019-BELMONTE DE TAJO/A.ES.SDGC.BU.28019.zip"              
 [17] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28021-BERZOSA DEL LOZOYA/A.ES.SDGC.BU.28021.zip"            
 [18] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28022-BOADILLA DEL MONTE/A.ES.SDGC.BU.28022.zip"            
 [19] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28024-BRAOJOS/A.ES.SDGC.BU.28024.zip"                       
 [20] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28025-BREA DE TAJO/A.ES.SDGC.BU.28025.zip"                  
 [21] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28026-BRUNETE/A.ES.SDGC.BU.28026.zip"                       
 [22] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28027-BUITRAGO DEL LOZOYA/A.ES.SDGC.BU.28027.zip"           
 [23] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28028-BUSTARVIEJO/A.ES.SDGC.BU.28028.zip"                   
 [24] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28029-CABANILLAS DE LA SIERRA/A.ES.SDGC.BU.28029.zip"       
 [25] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28031-CADALSO DE LOS VIDRIOS/A.ES.SDGC.BU.28031.zip"        
 [26] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28032-CAMARMA DE ESTERUELAS/A.ES.SDGC.BU.28032.zip"         
 [27] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28033-CAMPO REAL/A.ES.SDGC.BU.28033.zip"                    
 [28] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28034-CANENCIA/A.ES.SDGC.BU.28034.zip"                      
 [29] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28035-CARABAÑA/A.ES.SDGC.BU.28035.zip"                      
 [30] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28036-CASARRUBUELOS/A.ES.SDGC.BU.28036.zip"                 
 [31] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28037-CENICIENTOS/A.ES.SDGC.BU.28037.zip"                   
 [32] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28038-CERCEDILLA/A.ES.SDGC.BU.28038.zip"                    
 [33] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28039-CERVERA DE BUITRAGO/A.ES.SDGC.BU.28039.zip"           
 [34] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28051-CHAPINERIA/A.ES.SDGC.BU.28051.zip"                    
 [35] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28052-CHINCHON/A.ES.SDGC.BU.28052.zip"                      
 [36] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28040-CIEMPOZUELOS/A.ES.SDGC.BU.28040.zip"                  
 [37] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28041-COBEÑA/A.ES.SDGC.BU.28041.zip"                        
 [38] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28046-COLLADO MEDIANO/A.ES.SDGC.BU.28046.zip"               
 [39] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28047-COLLADO VILLALBA/A.ES.SDGC.BU.28047.zip"              
 [40] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28043-COLMENAR DE OREJA/A.ES.SDGC.BU.28043.zip"             
 [41] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28042-COLMENAR DEL ARROYO/A.ES.SDGC.BU.28042.zip"           
 [42] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28045-COLMENAR VIEJO/A.ES.SDGC.BU.28045.zip"                
 [43] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28044-COLMENAREJO/A.ES.SDGC.BU.28044.zip"                   
 [44] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28048-CORPA/A.ES.SDGC.BU.28048.zip"                         
 [45] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28049-COSLADA/A.ES.SDGC.BU.28049.zip"                       
 [46] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28050-CUBAS DE LA SAGRA/A.ES.SDGC.BU.28050.zip"             
 [47] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28053-DAGANZO DE ARRIBA/A.ES.SDGC.BU.28053.zip"             
 [48] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28004-EL ALAMO/A.ES.SDGC.BU.28004.zip"                      
 [49] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28016-EL ATAZAR/A.ES.SDGC.BU.28016.zip"                     
 [50] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28020-EL BERRUECO/A.ES.SDGC.BU.28020.zip"                   
 [51] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28023-EL BOALO/A.ES.SDGC.BU.28023.zip"                      
 [52] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28054-EL ESCORIAL/A.ES.SDGC.BU.28054.zip"                   
 [53] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28086-EL MOLAR/A.ES.SDGC.BU.28086.zip"                      
 [54] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28168-EL VELLON/A.ES.SDGC.BU.28168.zip"                     
 [55] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28055-ESTREMERA/A.ES.SDGC.BU.28055.zip"                     
 [56] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28056-FRESNEDILLAS DE LA OLIVA/A.ES.SDGC.BU.28056.zip"      
 [57] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28057-FRESNO DE TOROTE/A.ES.SDGC.BU.28057.zip"              
 [58] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28058-FUENLABRADA/A.ES.SDGC.BU.28058.zip"                   
 [59] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28059-FUENTE EL SAZ DE JARAMA/A.ES.SDGC.BU.28059.zip"       
 [60] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28060-FUENTIDUEÑA DE TAJO/A.ES.SDGC.BU.28060.zip"           
 [61] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28061-GALAPAGAR/A.ES.SDGC.BU.28061.zip"                     
 [62] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28062-GARGANTA DE LOS MONTES/A.ES.SDGC.BU.28062.zip"        
 [63] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28063-GARGANTILLA DEL LOZOYA Y PINIL/A.ES.SDGC.BU.28063.zip"
 [64] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28064-GASCONES/A.ES.SDGC.BU.28064.zip"                      
 [65] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28065-GETAFE/A.ES.SDGC.BU.28065.zip"                        
 [66] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28066-GRIÑON/A.ES.SDGC.BU.28066.zip"                        
 [67] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28067-GUADALIX DE LA SIERRA/A.ES.SDGC.BU.28067.zip"         
 [68] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28068-GUADARRAMA/A.ES.SDGC.BU.28068.zip"                    
 [69] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28070-HORCAJO DE LA SIERRA AOSLOS/A.ES.SDGC.BU.28070.zip"   
 [70] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28071-HORCAJUELO DE LA SIERRA/A.ES.SDGC.BU.28071.zip"       
 [71] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28072-HOYO DE MANZANARES/A.ES.SDGC.BU.28072.zip"            
 [72] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28073-HUMANES DE MADRID/A.ES.SDGC.BU.28073.zip"             
 [73] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28001-LA ACEBEDA/A.ES.SDGC.BU.28001.zip"                    
 [74] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28030-LA CABRERA/A.ES.SDGC.BU.28030.zip"                    
 [75] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28069-LA HIRUELA/A.ES.SDGC.BU.28069.zip"                    
 [76] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28138-LA SERNA DEL MONTE/A.ES.SDGC.BU.28138.zip"            
 [77] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28127-LAS ROZAS DE MADRID/A.ES.SDGC.BU.28127.zip"           
 [78] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28074-LEGANES/A.ES.SDGC.BU.28074.zip"                       
 [79] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28075-LOECHES/A.ES.SDGC.BU.28075.zip"                       
 [80] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28087-LOS MOLINOS/A.ES.SDGC.BU.28087.zip"                   
 [81] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28137-LOS SANTOS DE LA HUMOSA/A.ES.SDGC.BU.28137.zip"       
 [82] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28076-LOZOYA/A.ES.SDGC.BU.28076.zip"                        
 [83] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28077-LOZOYUELA NAVAS SIETEIGLESIAS/A.ES.SDGC.BU.28077.zip" 
 [84] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28078-MADARCOS/A.ES.SDGC.BU.28078.zip"                      
 [85] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28900-MADRID/A.ES.SDGC.BU.28900.zip"                        
 [86] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28080-MAJADAHONDA/A.ES.SDGC.BU.28080.zip"                   
 [87] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28082-MANZANARES EL REAL/A.ES.SDGC.BU.28082.zip"            
 [88] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28083-MECO/A.ES.SDGC.BU.28083.zip"                          
 [89] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28084-MEJORADA DEL CAMPO/A.ES.SDGC.BU.28084.zip"            
 [90] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28085-MIRAFLORES DE LA SIERRA/A.ES.SDGC.BU.28085.zip"       
 [91] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28088-MONTEJO DE LA SIERRA/A.ES.SDGC.BU.28088.zip"          
 [92] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28089-MORALEJA DE ENMEDIO/A.ES.SDGC.BU.28089.zip"           
 [93] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28090-MORALZARZAL/A.ES.SDGC.BU.28090.zip"                   
 [94] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28091-MORATA DE TAJUÑA/A.ES.SDGC.BU.28091.zip"              
 [95] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28092-MOSTOLES/A.ES.SDGC.BU.28092.zip"                      
 [96] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28093-NAVACERRADA/A.ES.SDGC.BU.28093.zip"                   
 [97] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28094-NAVALAFUENTE/A.ES.SDGC.BU.28094.zip"                  
 [98] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28095-NAVALAGAMELLA/A.ES.SDGC.BU.28095.zip"                 
 [99] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28096-NAVALCARNERO/A.ES.SDGC.BU.28096.zip"                  
[100] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28097-NAVARREDONDA Y SAN MAMES/A.ES.SDGC.BU.28097.zip"      
[101] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28099-NAVAS DEL REY/A.ES.SDGC.BU.28099.zip"                 
[102] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28100-NUEVO BAZTAN/A.ES.SDGC.BU.28100.zip"                  
[103] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28101-OLMEDA DE LAS FUENTES/A.ES.SDGC.BU.28101.zip"         
[104] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28102-ORUSCO DE TAJUÑA/A.ES.SDGC.BU.28102.zip"              
[105] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28104-PARACUELLOS DE JARAMA/A.ES.SDGC.BU.28104.zip"         
[106] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28106-PARLA/A.ES.SDGC.BU.28106.zip"                         
[107] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28107-PATONES/A.ES.SDGC.BU.28107.zip"                       
[108] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28108-PEDREZUELA/A.ES.SDGC.BU.28108.zip"                    
[109] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28109-PELAYOS DE LA PRESA/A.ES.SDGC.BU.28109.zip"           
[110] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28110-PERALES DE TAJUÑA/A.ES.SDGC.BU.28110.zip"             
[111] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28111-PEZUELA DE LAS TORRES/A.ES.SDGC.BU.28111.zip"         
[112] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28112-PINILLA DEL VALLE/A.ES.SDGC.BU.28112.zip"             
[113] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28113-PINTO/A.ES.SDGC.BU.28113.zip"                         
[114] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28114-PIÑUECAR GANDULLAS/A.ES.SDGC.BU.28114.zip"            
[115] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28115-POZUELO DE ALARCON/A.ES.SDGC.BU.28115.zip"            
[116] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28116-POZUELO DEL REY/A.ES.SDGC.BU.28116.zip"               
[117] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28117-PRADENA DEL RINCON/A.ES.SDGC.BU.28117.zip"            
[118] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28118-PUEBLA DE LA SIERRA/A.ES.SDGC.BU.28118.zip"           
[119] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28185-PUENTES VIEJAS/A.ES.SDGC.BU.28185.zip"                
[120] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28119-QUIJORNA/A.ES.SDGC.BU.28119.zip"                      
[121] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28120-RASCAFRIA/A.ES.SDGC.BU.28120.zip"                     
[122] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28121-REDUEÑA/A.ES.SDGC.BU.28121.zip"                       
[123] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28122-RIBATEJADA/A.ES.SDGC.BU.28122.zip"                    
[124] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28123-RIVAS VACIAMADRID/A.ES.SDGC.BU.28123.zip"             
[125] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28124-ROBLEDILLO DE LA JARA/A.ES.SDGC.BU.28124.zip"         
[126] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28125-ROBLEDO DE CHAVELA/A.ES.SDGC.BU.28125.zip"            
[127] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28126-ROBREGORDO/A.ES.SDGC.BU.28126.zip"                    
[128] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28128-ROZAS DE PUERTO REAL/A.ES.SDGC.BU.28128.zip"          
[129] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28129-SAN AGUSTIN DEL GUADALIX/A.ES.SDGC.BU.28129.zip"      
[130] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28130-SAN FERNANDO DE HENARES/A.ES.SDGC.BU.28130.zip"       
[131] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28131-SAN LORENZO DE EL ESCORIAL/A.ES.SDGC.BU.28131.zip"    
[132] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28132-SAN MARTIN DE LA VEGA/A.ES.SDGC.BU.28132.zip"         
[133] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28133-SAN MARTIN DE VALDEIGLESIAS/A.ES.SDGC.BU.28133.zip"   
[134] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28134-SAN SEBASTIAN DE LOS REYES/A.ES.SDGC.BU.28134.zip"    
[135] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28135-SANTA MARIA DE LA ALAMEDA/A.ES.SDGC.BU.28135.zip"     
[136] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28136-SANTORCAZ/A.ES.SDGC.BU.28136.zip"                     
[137] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28140-SERRANILLOS DEL VALLE/A.ES.SDGC.BU.28140.zip"         
[138] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28141-SEVILLA LA NUEVA/A.ES.SDGC.BU.28141.zip"              
[139] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28143-SOMOSIERRA/A.ES.SDGC.BU.28143.zip"                    
[140] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28144-SOTO DEL REAL/A.ES.SDGC.BU.28144.zip"                 
[141] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28145-TALAMANCA DE JARAMA/A.ES.SDGC.BU.28145.zip"           
[142] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28146-TIELMES/A.ES.SDGC.BU.28146.zip"                       
[143] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28147-TITULCIA/A.ES.SDGC.BU.28147.zip"                      
[144] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28148-TORREJON DE ARDOZ/A.ES.SDGC.BU.28148.zip"             
[145] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28149-TORREJON DE LA CALZADA/A.ES.SDGC.BU.28149.zip"        
[146] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28150-TORREJON DE VELASCO/A.ES.SDGC.BU.28150.zip"           
[147] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28151-TORRELAGUNA/A.ES.SDGC.BU.28151.zip"                   
[148] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28152-TORRELODONES/A.ES.SDGC.BU.28152.zip"                  
[149] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28153-TORREMOCHA DE JARAMA/A.ES.SDGC.BU.28153.zip"          
[150] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28154-TORRES DE LA ALAMEDA/A.ES.SDGC.BU.28154.zip"          
[151] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28184-TRES CANTOS/A.ES.SDGC.BU.28184.zip"                   
[152] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28155-VALDARACETE/A.ES.SDGC.BU.28155.zip"                   
[153] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28156-VALDEAVERO/A.ES.SDGC.BU.28156.zip"                    
[154] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28157-VALDELAGUNA/A.ES.SDGC.BU.28157.zip"                   
[155] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28158-VALDEMANCO/A.ES.SDGC.BU.28158.zip"                    
[156] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28159-VALDEMAQUEDA/A.ES.SDGC.BU.28159.zip"                  
[157] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28160-VALDEMORILLO/A.ES.SDGC.BU.28160.zip"                  
[158] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28161-VALDEMORO/A.ES.SDGC.BU.28161.zip"                     
[159] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28162-VALDEOLMOS ALALPARDO/A.ES.SDGC.BU.28162.zip"          
[160] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28163-VALDEPIELAGOS/A.ES.SDGC.BU.28163.zip"                 
[161] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28164-VALDETORRES DE JARAMA/A.ES.SDGC.BU.28164.zip"         
[162] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28165-VALDILECHA/A.ES.SDGC.BU.28165.zip"                    
[163] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28166-VALVERDE DE ALCALA/A.ES.SDGC.BU.28166.zip"            
[164] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28167-VELILLA DE SAN ANTONIO/A.ES.SDGC.BU.28167.zip"        
[165] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28169-VENTURADA/A.ES.SDGC.BU.28169.zip"                     
[166] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28171-VILLA DEL PRADO/A.ES.SDGC.BU.28171.zip"               
[167] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28170-VILLACONEJOS/A.ES.SDGC.BU.28170.zip"                  
[168] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28172-VILLALBILLA/A.ES.SDGC.BU.28172.zip"                   
[169] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28173-VILLAMANRIQUE DE TAJO/A.ES.SDGC.BU.28173.zip"         
[170] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28174-VILLAMANTA/A.ES.SDGC.BU.28174.zip"                    
[171] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28175-VILLAMANTILLA/A.ES.SDGC.BU.28175.zip"                 
[172] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28176-VILLANUEVA DE LA CAÑADA/A.ES.SDGC.BU.28176.zip"       
[173] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28178-VILLANUEVA DE PERALES/A.ES.SDGC.BU.28178.zip"         
[174] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28177-VILLANUEVA DEL PARDILLO/A.ES.SDGC.BU.28177.zip"       
[175] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28179-VILLAR DEL OLMO/A.ES.SDGC.BU.28179.zip"               
[176] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28180-VILLAREJO DE SALVANES/A.ES.SDGC.BU.28180.zip"         
[177] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28181-VILLAVICIOSA DE ODON/A.ES.SDGC.BU.28181.zip"          
[178] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28182-VILLAVIEJA DEL LOZOYA/A.ES.SDGC.BU.28182.zip"         
[179] "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28183-ZARZALEJO/A.ES.SDGC.BU.28183.zip"                     
urlB <- ( "http://www.catastro.minhap.es/INSPIRE/Buildings/28/28047-COLLADO VILLALBA/A.ES.SDGC.BU.28047.zip")

destination<- "C:/Users/polo/OneDrive/ZZZ/vivienda/catastro/A.ES.SDGC.BU.28047.zip"

download.file(urlB, destination)
data(catr_srs_values)

library(dplyr)

catr_srs_values %>% filter(ovc_service == TRUE)
# A tibble: 14 x 4
     SRS Description            ovc_service wfs_service
   <dbl> <chr>                  <lgl>       <lgl>      
 1  4230 Geográficas en ED 50   TRUE        FALSE      
 2  4258 Geográficas en ETRS89  TRUE        TRUE       
 3  4326 Geográficas en WGS 80  TRUE        TRUE       
 4 23029 UTM huso 29N en ED50   TRUE        FALSE      
 5 23030 UTM huso 30N en ED50   TRUE        FALSE      
 6 23031 UTM huso 31N en ED50   TRUE        FALSE      
 7 25829 UTM huso 29N en ETRS89 TRUE        TRUE       
 8 25830 UTM huso 30N en ETRS89 TRUE        TRUE       
 9 25831 UTM huso 31N en ETRS89 TRUE        TRUE       
10 32627 UTM huso 27N en WGS 84 TRUE        FALSE      
11 32628 UTM huso 28N en WGS 84 TRUE        FALSE      
12 32629 UTM huso 29N en WGS 84 TRUE        FALSE      
13 32630 UTM huso 30N en WGS 84 TRUE        FALSE      
14 32631 UTM huso 31N en WGS 84 TRUE        FALSE      
catr_atom_search_munic("Mad")
# A tibble: 40 x 3
   territorial_office             munic                              catrcode
   <chr>                          <chr>                              <chr>   
 1 Territorial office 02 Albacete 02045-MADRIGUERAS                  02045   
 2 Territorial office 02 Albacete 02058-PATERNA DEL MADERA           02058   
 3 Territorial office 05 Avila    05114-MADRIGAL DE LAS ALTAS TORRES 05114   
 4 Territorial office 09 Burgos   09178-HUMADA                       09178   
 5 Territorial office 09 Burgos   09187-JARAMILLO QUEMADO            09187   
 6 Territorial office 09 Burgos   09200-MADRIGAL DEL MONTE           09200   
 7 Territorial office 09 Burgos   09201-MADRIGALEJO DEL MONTE        09201   
 8 Territorial office 09 Burgos   09287-QUEMADA                      09287   
 9 Territorial office 10 Cáceres  10114-MADRIGAL DE LA VERA          10114   
10 Territorial office 10 Cáceres  10115-MADRIGALEJO                  10115   
# ... with 30 more rows
library(maps); library(ggplot2); library(mapproj) 

# install.packages("maps")
# install.packages("mapproj")

states <- map_data("state") 
usamap <- ggplot(states, aes(x=long, y=lat, group=group)) +  geom_polygon(fill="white", colour="black") 
usamap + coord_map("mercator")

# usamap + coord_map("azequalarea")